package com.imooc.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by zghgchao 2018/4/15 16:52
 */
//@Aspect
//@Component
public class TimeAspect {

    // *：返回类型    *：方法   (..)：所有参数
    @Around("execution(* com.imooc.web.controller.UserController.*(..))")
    public Object handlerControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("time aspect start");
        long start = new Date().getTime();

        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            System.out.println("arg is :"+arg);
        }

        Object object = pjp.proceed();//去掉真正拦截的那个方法

        System.out.println("time aspect 耗时: "+(new Date().getTime()-start));

        System.out.println("time aspect end");

        return object;
    }
}
